package com.dataaccess.dataaccess.web.web;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseController;
import com.dataaccess.dataaccess.model.AlarmAllDeviceDataChanged;
import com.dataaccess.dataaccess.support.annotaion.Action;
import com.dataaccess.dataaccess.support.annotaion.At;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.web.mapper.AlarmAllDeviceDataChangedMapper;
import com.dataaccess.dataaccess.web.service.PaiAnSmokeGatewaysService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author: YangYu
 * @ClassName: PaiAnSmokeGatewaysController
 * @Date: Created in 10:40 2021/10/27
 */
@Action
@RequestMapping("paiAnSmokeGateways")
public class PaiAnSmokeGatewaysController extends BaseController {


    @Resource
    PaiAnSmokeGatewaysService paiAnSmokeGatewaysService;
    @Resource
    private AlarmAllDeviceDataChangedMapper alarmAllDeviceDataChangedMapper;
    @Resource
    public MyLogger logger;
    /**
     * @Author YangYu
     * @Description  派安烟感网关数据变化
     * @Date Created in 17:29 2021/10/27
     * @Param [jsonParam]
     */

    @At(value = "info", method = RequestMethod.POST)
    public RespEntity smokeGateways(@RequestBody(required = false) JSONObject jsonParam) throws Exception  {
        logger.info("paiAnSmokeGatewaysDataChanged"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("SmokeGateways");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        return paiAnSmokeGatewaysService.smokeGateways(jsonParam);
    }

    /**
     * @Author YangYu
     * @Description  派安烟感网关数据变化(lora第三方平台)
     * @Date Created in 17:29 2021/10/27
     * @Param [jsonParam]
     */

    @At(value = "info_lora", method = RequestMethod.POST)
    public RespEntity smokeGatewaysLora(@RequestBody(required = false) JSONObject jsonParam) throws Exception  {
        logger.info("smokeGatewaysLora"+"------"+jsonParam);
        //报警数据
        AlarmAllDeviceDataChanged alarmAllDeviceDataChanged = new AlarmAllDeviceDataChanged();
        alarmAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        alarmAllDeviceDataChanged.setJsondata(jsonParam.toString());
        alarmAllDeviceDataChanged.setType("smokeGatewaysLora");
        alarmAllDeviceDataChangedMapper.insert(alarmAllDeviceDataChanged);
        return paiAnSmokeGatewaysService.smokeGatewaysLora(jsonParam);
    }


}
